package cn.gz.zoomtech.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ToolBean {

	private static final Log log = LogFactory.getLog(ToolBean.class);

	/**
	 * 
	 * 功能描述: 过滤掉字符串中左边的0字符,返回表示数量的字符串
	 * 
	 * @param str
	 * @return
	 * @author chenhui / 2009-11-16 下午04:43:37
	 */
	public static String getStandleStr(String str) {
		try {
			for (int i = 0; i < str.length(); i++) {
				if (!(str.substring(i, i + 1)).equals("0")) {
					str = str.substring(i, str.length());
					break;
				}
			}
		} catch (Exception e) {
			log.error("strChangeError:", e);
		}
		return str;
	}

	/**
	 * 
	 * 功能描述: 将字符串数字，转化成需要的长度，左补0
	 * 
	 * @param str
	 * @param len
	 * @return
	 * @author chenhui / 2009-11-16 下午04:45:23
	 */
	public static String getStadNumStr(String str, int len) {
		String returnStr="";
//		System.out.println("str is:"+str+",len is:"+len);
		try {
			if(str==null||"".equals(str.trim())){
				for(int i=0;i<len;i++){
					returnStr="0"+returnStr;
				}
			}else if(str.length()>len){
				returnStr = str.substring(0, len);
			}else{
//				System.out.println("str.length() is:"+str.length());
				for (int i = 0; i < (len-str.length()); i++) {
					returnStr = returnStr+"0";					
				}// end for
				returnStr = returnStr+str;
			}// end else
			
		} catch (Exception e) {
			log.error("strChangeError:", e);
		}
		return returnStr;
	}
	/**
	 * 
	* 功能描述: 根据需要的字符串长度，右补空格
	* @param str
	* @param len
	* @return
	* @author chenhui / 2009-11-16 下午05:00:32
	 */
	public static String getStadConetentStr(String str, int len) {
		String returnStr="";
//		System.out.println("str is:"+str+",len is:"+len);
		try {
			if(str==null||"".equals(str.trim())){
				for(int i=0;i<len;i++){
					returnStr=returnStr+" ";
				}
			}else if(str.length()>len){
				returnStr = str.substring(0, len);
			}else{
				for (int i = 0; i < (len-str.length()); i++) {
					returnStr = returnStr+" ";					
				}// end for
				returnStr = str+returnStr;
			}// end else
			
		} catch (Exception e) {
			log.error("strChangeError:", e);
		}
		return returnStr;
	}
	/**
	 * 
	* 功能描述: 检验字符串是否为空或null，并返回。
	* @param str
	* @return
	* @author chenhui / 2009-12-18 上午10:08:38
	 */
	public static String checkString(String str){
		String value = null;
		try{
			if(str==null||"".equals(str.trim())){
				return null;
			}else{
				value = str.trim();
			}
		}catch(Exception e){
			value = null;
			return value;
		}finally{
			
		}
		return value;
	}
	/**
	 * 
	* 功能描述: 检验非数字字符串，返回对应结果。
	* @param str
	* @return
	* @author chenhui / 2009-12-18 上午10:08:42
	 */
	public static Integer changeStrToInteger(String str){
		Integer value = null;
		try{
			if(str==null||"".equals(str.trim())){
				return null;
			}else{
				value = Integer.decode(str.trim());
			}
		}catch(Exception e){
			value = null;
			return value;
		}finally{
			
		}
		return value;
	}
	
	/**
	 * 
	* package_name: cn.gz.zoomtech.common
	* file_name:    ToolBean.java
	* description: 根据UISP的返回码，生成定位结果描述内容
	* 2013-2-5上午11:20:32
	* Author: chenhui
	 * @param code
	 * @return
	 * 128 assumedIdle=0x0080;// (空闲)
       129 camelBusy=0x0081;// (用户忙)
       130 notProvidedFromVLR=0x0082;//（VLR位置寄存器不提供号码信息）
       2560 msPurged=0x0a00;// (用户不可及，相当于关机)
       2561 imsiDetached=0x0a01;//(关机)
       2562 restrictedArea=0x0a02;//(用户在限制区域)
       2563 notRegistered=0x0a03;//(未注册)
       27 AbsentSubscriber=0x001b; //（缺席用户）
       
       5008：UISP定位超时
       109：非白名单,禁止定位
       110：本地数据库未存此基站信息
       0: 基站经纬值
       1：基站中心经纬值
	 */
	public static String getCellMemoByUispCode(short code){
		String memo = "";
		try{
			switch(code){
				
			case 0:
				memo = "基站经纬值";
				break;	
				
			case 1:
				memo = "基站中心经纬值";
				break;			
				
				
			case 109:
				memo = "非白名单,禁止定位";
				break;	
				
			case 110:
				memo = code+":本地数据库未存此基站信息";
				break;			
			
			case 128:
				memo = code+":空闲";
				break;
				
			case 129:
				memo = code+":用户忙";
				break;
				
			case 130:
				memo = code+":VLR位置寄存器不提供号码信息";
				break;	
				
			case 2560:
				memo = code+":用户不可及，相当于关机";
				break;	
				
			case 2561:
				memo = code+":关机";
				break;	
				
			case 2562:
				memo = code+":用户在限制区域";
				break;	
				
			case 2563:
				memo = code+":未注册";
				break;	
				
			case 27:
				memo = code+":缺席用户";
				break;	
				
			case 5008:
				memo = code+":UISP定位超时";
				break;		
				
			default:
				memo = code+":返回码未知";
				break;	
			}			
		}catch(Exception ex){
			log.error(code+",createMemoError:",ex);
		}
			return memo;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
	
		short memoCode = 2562;
		String value = ToolBean.getCellMemoByUispCode(memoCode);
        System.out.println(value);
	}

}
